const state = {
  userList: [],
};

const mutations = {
  SET_USERLIST: (state, userList) => {
    state.userList = userList;
  },
  EMPTY: () => {},
};

const actions = {
  // get userList
  getUserList({ commit }, query) {
    return new Promise((resolve, reject) => {
      // api getUserList
      getUserListApi(query)
        .then((res) => {
          commit("SET_USERLIST", res);
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // editUser action
  editUser({ commit }, query) {
    return new Promise((resolve, reject) => {
      editUserListApi(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  // reset password
  resetPassword({ commit }, query) {
    return new Promise((resolve, reject) => {
      resetPwdApi(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //unlock/lock user
  lockUser({ commit }, query) {
    return new Promise((resolve, reject) => {
      lockedUserApi(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //获取审核消息
  getMessage({ commit }, query) {
    return new Promise((resolve, reject) => {
      getMessage(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //已读接口
  haveRead({ commit }, query) {
    return new Promise((resolve, reject) => {
      haveRead(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //更改密码
  changePassword({ commit }, query) {
    return new Promise((resolve, reject) => {
      changePassword(query)
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  heartbeat({ commit }) {
    return new Promise((resolve, reject) => {
      heartbeat()
        .then((res) => {
          commit("EMPTY");
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
